package com.wcl.demo.ui.activity;

import android.content.Intent;
import android.graphics.Paint;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.easemob.EMError;
import com.easemob.chat.EMChatManager;
import com.easemob.exceptions.EaseMobException;
import com.wcl.demo.R;
import com.wcl.demo.db.UserHelper;
import com.wcl.demo.presenter.BasePresenter;
import com.wcl.demo.presenter.RegisterPresenter;
import com.wcl.demo.ui.ViewInterface.ViewRegisterInterface;
import com.wcl.demo.utils.ActivityUtils;
import com.wcl.demo.view.CustomToast;
import com.wcl.demo.utils.ProgressUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by dllo on 15/11/19.
 */
public class RegisterActivity extends MVPBaseActivity<ViewRegisterInterface, RegisterPresenter> implements ViewRegisterInterface {

    @Bind(R.id.register_agreement)
    TextView register_agreement;
    @Bind(R.id.register_username)
    EditText register_username;
    @Bind(R.id.register_password)
    EditText register_password;
    @Bind(R.id.rgister_againpassword)
    EditText rgister_againpassword;

    @Override
    protected int getLayout() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        register_agreement.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    }

    @OnClick(R.id.register_back)
    void register_back() {
        finish();
    }

    @OnClick(R.id.register_login)
    void register_login() {
        userRegister();
    }

    /***
     * 用户注册
     */

    public void  userRegister(){
        Map<String, String> map = new HashMap<>();
        final String user_name = register_username.getText().toString().trim();
        final String user_psw = register_password.getText().toString().trim();
        String user_confirm_psw = rgister_againpassword.getText().toString().trim();
        map.put("user_name", user_name);
        map.put("user_psw", user_psw);
        map.put("user_confirm_psw", user_confirm_psw);
        createPresenter().startRegister(map);
    }

    @Override
    protected RegisterPresenter createPresenter() {
        return new RegisterPresenter(this);
    }

    @Override
    public void showResult(String Str) {
        Toast.makeText(this,Str,Toast.LENGTH_SHORT).show();
        ActivityUtils.startToActivity(this , LoginActivity.class);
    }
}
